const { Sequelize } = require("sequelize");

const sequelize = new Sequelize("novel", "root", "Qian1234056.", {
	host: "localhost",
	dialect: "mysql",
	dialectOptions: {
		charset: "utf8mb4", // 设置字符集
	},
	define: {
		charset: "utf8mb4", // 设置模型默认字符集（对新创建的表有效）
		collate: "utf8mb4_unicode_ci", // 设置模型默认排序规则（对新创建的表有效）
		timestamps: false, // 如果不需要自动添加 createdAt 和 updatedAt 字段可以设置为 false
	},
	logging: false,
});

try {
	sequelize.authenticate();
	console.log("Connection has been established successfully.");
} catch (error) {
	console.error("Unable to connect to the database:", error);
}

module.exports = sequelize;
